package com.zerox.convert;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateConvert implements Converter<String, Date> {
    private String patten = "yyyy-MM-dd";

    public void setPatten(String patten) {
        this.patten = patten;
    }

    SimpleDateFormat format = new SimpleDateFormat(patten);

    @Override
    public Date convert(String s) {
        Date date = null;
        try {
            date = format.parse(s);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
